<template>
  <div >
    <form class="form-horizontal upload-block" id="upload">
      <el-upload
          class="upload-demo"
          ref="upload"
          action="http://39.105.175.112:8080/api/v1/excel"
          :limit="1"
          accept='.xlsx'
          :on-success="uploadSuccess"
          :on-error="uploadError">
        <el-button type="primary">上传<i class="el-icon-upload el-icon--right"></i></el-button>
      </el-upload>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
    };
  },
  methods: {
    //文件上传事件
    uploadSuccess(res) {
      console.log(res);
      this.removeList();
      this.$message({  //弹窗
        message: 'Excel导入成功',
        type: 'success',
        center: true,
        duration: 2500
      });


    },
    uploadError(res){
      console.log(res);

      this.$message({  //弹窗
        type: 'error',
        message: 'Excel导入失败！',
        center: true,
        duration: 2500
      });
      this.$refs.upload.clearFiles(); //去掉文件列表
    },
    removeList(){
      let  _this=this
      setTimeout(function (){
        _this.$refs.upload.clearFiles(); //去掉文件列表
      },1000)
    }
  }
}
</script>
